<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Map;" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="<%=request.getContextPath()%>/public/css/style.model.css">
<!-- core -->
<script src="<%=request.getContextPath()%>/public/js/jquery-1.5.1.min.js"></script>
</head>
<body>
<div class="container">
<h2><c:out value="${model.m_title }"/></h2>
<form action='<%=request.getContextPath()%>/c?<c:out value="${ model.m_action }"/>&m_id=${model.m_id}&o=${p}&v=${v}&pri=${pri}&key=${key}' class='<c:out value="${ model.m_attr_class }"/>'  method="post" <c:out value="${ model.m_attr_other }"/> id='<c:out value="${ model.m_attr_id }"/>' >
<fieldset>
<h4><c:if test="${p eq 'edit' }">修改</c:if><c:if test="${p eq 'add' }">新增</c:if></h4>
<%  Object o =request.getAttribute("e");
Map<String,Object> e = null;
if(null!=o){ e = (Map<String,Object>)o; }%>
<c:forEach var="control" items="${controls }" >
<c:set var="attr_name" value="${control.mc_attr_name }" scope="request"/>
<c:if test="${!control.mc_auto}">
<c:if test="${p eq 'edit' }">
<%  request.setAttribute("v", e.get(request.getAttribute("attr_name").toString())); %>
</c:if>
<div class="form-line">
	<label>${control.mc_prompt }:</label>
	<span class="${control.c_attr_class }">
	<c:choose>
    <c:when test="${control.c_tag eq 'textarea'}">
	<textarea name="${control.mc_attr_name }" class="txtarea"><c:if test="${p eq 'add' }">${control.mc_def_val }</c:if><%= e!=null?e.get(request.getAttribute("attr_name").toString()):"" %></textarea>
    </c:when>
    <c:when test="${control.c_tag eq 'select'}">
    <select class="field">
    	<c:forEach var="ds" items="${control.mc_ds }">
    	<option value="${ds.k }" <c:if test="${ds.k eq v}">selected='selected'</c:if> >${ds.v }</option>
    	</c:forEach>
    </select>
    </c:when>
    <c:when test="${control.c_tag eq 'radio'}">
    
    </c:when>  
    <c:when test="${control.c_tag eq 'toggle'}">
    <% boolean b = e!=null?Boolean.parseBoolean(request.getAttribute("v").toString()):("1".equals(request.getAttribute("p")));
       String v ="0";
       if(b)
    	   v = "1";
    %>
    <input type="checkbox" class="toggle-radio" <%= "1".equals(v)?"checked='checked'":"" %>><input name="${control.mc_attr_name }" value="<%= v%>" type="hidden"/>
    </c:when>      
    <c:otherwise>
    <input type="${control.c_tag }" name="${control.mc_attr_name }" class="field" value='<c:if test="${p eq 'add' }">${control.mc_def_val }</c:if><%= e!=null?request.getAttribute("v").toString():"" %>'/>
    </c:otherwise>  
    </c:choose>
	</span>
	<span class="tip">${control.mc_tip }</span>
</div>
<div class="cl"></div>
</c:if>
</c:forEach>
<div class="form-line">
	<button class="btn save">保存</button><button class="btn cancel">取消</button>
</div>
<div class="cl"></div>
</fieldset>
</form>
</div>
<script type="text/javascript">
	$().ready(function(){
		$(".toggle-radio").each(function(){
			$(this).click(function(){
				var v = parseInt($(this).next().val());
				$(this).next().val(v==1?0:1);
			});
		});
		$(".cancel").click(function(){
			if(!confirm('您未保存当前数据，且定要离开么?'))
				return false;
			history.go(-1);
			return false;
		});
	});
</script>
</body>
</html>